package cn.dlc.com.lock;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class RedissonLock {
	
	@Autowired
	private Environment env;

	@Bean
	public RLock rLock() {
		Config config = new Config();
		// 设置地址，地址需要是这样的redis://192.168.182.93:6379
//		config.useSingleServer().setAddress(env.getProperty("spring.redis.url"));
		config.useClusterServers().addNodeAddress(env.getProperty("spring.redis.url"));
		RedissonClient redisson = Redisson.create(config);
		RLock lock = redisson.getLock("lockName");
		return lock;
	}
}
